<template>
  <div>
    <el-drawer
      title="评论区"
      :visible.sync="drawerVisible.drawer1"
      direction="rtl"
      size="350px"
      :modal="false"
      :show-close="false"
      custom-class="draw-comments"
      @close="closeDrawer('drawer1')"
    >
      <div class="user-comments">
        <div
          class="each-comments"
          v-for="(comment,index) in cardCommentInfo"
          :key="index"
        >
          <div class="comInfo">
            <p>{{comment.username}}</p>
            <div><img
                v-if="comment.user_pic"
                :src="comment.user_pic"
                alt=""
              >

              <img
                v-else
                src="../../../../assets/avatar1.svg"
                alt=""
              >
            </div>
          </div>
          <div class="comment-words">
            <p>{{$formatDate(comment.moment)}}</p>
            <span>
              {{comment.message}}

            </span>
          </div>
        </div>

      </div>
      <div class="feedback-form">
        <h1 class="form-title">发表评论</h1>
        <textarea
          class="feedback-input"
          placeholder=" 写下你的评论"
          v-model="message"
        ></textarea>
        <div class="spacer"><button
            class="secondary-button"
            @click="addHelpComment()"
          >
            <svg
              width="30px"
              height="30px"
              xmlns="http://www.w3.org/2000/svg"
              fill="none"
            >
              <path
                d="M7.39999 6.32003L15.89 3.49003C19.7 2.22003 21.77 4.30003 20.51 8.11003L17.68 16.6C15.78 22.31 12.66 22.31 10.76 16.6L9.91999 14.08L7.39999 13.24C1.68999 11.34 1.68999 8.23003 7.39999 6.32003Z"
                stroke-width="1.5"
                stroke-linecap="round"
                stroke-linejoin="round"
              ></path>
              <path
                d="M10.11 13.6501L13.69 10.0601"
                stroke-width="1.5"
                stroke-linecap="round"
                stroke-linejoin="round"
              ></path>
            </svg>
          </button></div>

      </div>
    </el-drawer>
    <div class="myHelpCard-container">
      <div
        class="card"
        @click="cardClick()"
      >
        <div
          class="mask"
          v-if="isMask"
        >
          <svg
            class="icon"
            aria-hidden="true"
          >
            <use xlink:href="#icon-yirenling1"></use>
          </svg>
        </div>
        <div class="card-image">
          <img
            v-if="!card.img_url"
            src="../../../../assets/avatar1.svg"
            alt=""
          >
          <img
            v-else
            :src="card.img_url"
            alt=""
          >
        </div>
        <p class="card-title"></p>
        <p class="card-body">
          {{card.message}}
        </p>
        <div class="card-footer">
          <div class="main-footer">
            <div class="cardUserInfo">
              <div class="uesrInfo-img"><img
                  v-if="card.user_pic"
                  :src="card.user_pic"
                  alt=""
                >
                <img
                  v-else
                  src="../../../../assets/avatar1.svg"
                  alt=""
                >
              </div>
              <span>{{card.username}}</span>

            </div>
            <div class="comLike">
              <div class="comment">
                <div class="foot-com">
                  <svg
                    class="icon"
                    aria-hidden="true"
                  >
                    <use xlink:href="#icon-pinglun-08"></use>
                  </svg>
                  <span>
                    {{card.comment_num}}
                  </span>
                </div>

              </div>

            </div>
            <div
              class="delBtn"
              @click.stop
            >
              <button
                class="custom-button"
                @click="deleteMyHelp"
              >
                删除
              </button>
            </div>
          </div>
          <div class="footer-time">
            <span>
              {{$formatDate2(card.moment)}}
            </span>
          </div>
        </div>
      </div>

    </div>

  </div>
</template>

<script>
import {
  getHelpGoodsCommentAPI,
  addHelpGoodsCommentAPI,
  deleteMyHelpGoodsAPI,
} from "@/api";

export default {
  data() {
    return {
      message: "",
      isMask: false,
      helpImg: false,
      drawerVisible: {
        drawer1: false,
        drawer2: false,
      },
      cardCommentInfo: [],
    };
  },
  props: ["card"],
  methods: {
    hadMaster() {
      this.isMask = true;
    },
    rebackMask() {
      this.isMask = false;
    },
    // 开关抽屉
    openDrawer(drawerName) {
      console.log(drawerName);
      if (drawerName == "drawer1") {
        this.drawerVisible.drawer1 = true;
      } else {
        this.drawerVisible.drawer2 = true;
      }
    },
    closeDrawer(drawername) {
      if (drawername == "drawer1") {
        this.drawerVisible.drawer1 = false;
      } else {
        this.drawerVisible.drawer2 = false;
      }
    },

    cardClick() {
      this.getHelpComment();
      this.openDrawer("drawer1");
    },
    // 发布评论
    async addHelpComment() {
      const data = {
        message: this.message,
        lost_id: this.card.id,
      };
      this.message = "";
      const res = await addHelpGoodsCommentAPI(data);
      console.log("ttttt", res);
      this.getHelpComment();
      this.$store.dispatch("initHelpGoods");
      this.$store.dispatch("initMyHelpCards");
    },
    // 获取卡片评论
    async getHelpComment() {
      let { data: res } = await getHelpGoodsCommentAPI(this.card.id);

      this.cardCommentInfo = res;
    },
    async deleteMyHelp() {
      const res = await deleteMyHelpGoodsAPI(this.card.id);
      this.$store.dispatch("initHelpGoods");
      this.$store.dispatch("initMyHelpCards");
    },
  },
};
</script>
 
 <style lang="less" scoped>
// 卡片footer底部
.main-footer {
  display: flex;
  width: 100%;
  justify-content: center;
  align-items: center;
}
// 时间
.footer-time {
  opacity: 0.5;
  display: flex;
  width: 100%;
  justify-content: flex-end;
  align-items: center;
}
//  卡片主容器·
.myHelpCard-container {
  display: flex;
  position: relative;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
// 卡片删除按钮
// 删除按钮
//删除按钮
.delBtn {
  display: flex;
  justify-content: flex-end;
}
.custom-button {
  cursor: pointer;
  transition: all 0.3s ease;
  background-color: #b5a8ff; /* 蓝色背景 */
  color: #fff; /* 白色文本 */
  padding: 0.2rem 0.8rem; /* 设置按钮内边距 */
  border-radius: 0.5rem; /* 设置圆角 */
  border: 2px solid #917ff9; /* 蓝色边框 */
  box-sizing: border-box;
  cursor: pointer;
}
.custom-button:hover {
  background-color: #8773f7; /* 蓝色背景 */
}
.custom-button:active {
  transform: scale(0.8);
}

/* 提交图片滚动条样式 */
/*定义滚动条宽度和颜色*/
.pre_img::-webkit- {
  width: 4px;
}

.pre_img::-webkit-scrollbar-track {
  background: #d2f3ef;
}

.pre_img::-webkit-scrollbar-thumb {
  background: #94f0f0;
}

/* 悬停效果 */
.pre_img::-webkit-scrollbar-thumb:hover {
  background: #5cd0f4;
}
/*提交按钮 */
.el-button--success {
  margin-bottom: 20px;
}

/* 商品上传用户头像 */

/* 商品上传头像信息 */

.img-word {
  width: 100%;
  display: flex;
  justify-content: start;
  align-items: center;
  margin-bottom: 10px;
  opacity: 0.8;
}

.buy-img {
  display: flex;
  width: 100%;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.pre_img {
  width: 250px;
  height: 250px;
  overflow-y: auto;
  border: 1px solid;
  margin-bottom: 15px;
}
.pre_img > img {
  width: 100%;
  height: auto;
}
/* 结束 */
/* 物品说明介绍 */
.buy-dir {
  width: 100%;
  height: 40%;
  display: flex;

  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-bottom: 10px;
  margin-top: -10px;
  opacity: 0.6;
}
.userWords {
  display: flex;
  background-color: #acdccec3;
  margin-top: 4px;
  width: 100%;
  height: 40%;
  padding: 10px;
  justify-content: center;
  align-items: center;
  position: relative;
  box-sizing: border-box;
  max-width: 300px;
  font-family: cursive;
  font-size: 20px;
  border-radius: 10px;
  background: #fff;
  background-image: linear-gradient(#f5f5f0 1.1rem, #ccc 1.2rem);
  background-size: 100% 1.2rem;
  line-height: 1.45rem;
  padding: 0.5rem 0.2rem 0.1rem 0.1rem;
}
/* textarea */
.message {
  background: none;
  /* border: none; */
  border: none;
  resize: none;
  outline: none;
  box-sizing: border-box;
  padding: 8px;
  width: 100%;
  height: 100%;
  margin-top: 12px;
}

.userWords > span {
  width: 96%;
  height: 90%;
  overflow: auto; /* 溢出隐藏 */
  text-align: center;
}
/*定义滚动条宽度和颜色*/
.userWords-span::-webkit-scrollbar {
  width: 4px;
}

.userWords-span::-webkit-scrollbar-track {
  background: #d2f3ef;
}

.userWords-span::-webkit-scrollbar-thumb {
  background: #94f0f0;
}

/* 悬停效果 */
.userWords-span::-webkit-scrollbar-thumb:hover {
  background: #5cd0f4;
}

/* 结束 */

.container {
  display: flex;
  flex-wrap: wrap; /* 当超出容器宽度时自动换行 */
  height: 100%;
  justify-content: center;
  align-items: center;
}
.icon {
  width: 90%;
  height: 90%;
}
.reback-btn {
  width: 33px;
  height: 33px;
  opacity: 0.8;
  cursor: pointer;
}
// mask 蒙层
.mask {
  display: flex;
  position: absolute;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 65%;
  opacity: 0.7;
  top: 0;
  left: 0;
  background-color: #c3c3c3;
  border-radius: 10px;
}
.mask.mask-active {
  display: flex;
}

/* 编辑按钮 */
.edit-button {
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #e8e8e8;
  background-color: #959ff8;
  width: 60px;
  height: 60px;
  font-size: 24px;
  text-transform: uppercase;
  border: 2px solid #5bd6fcbb;
  border-radius: 50%;
  transition: all 0.6s cubic-bezier(0.23, 1, 0.32, 1);
  box-shadow: 5px 5px 2px rgba(0, 0, 0, 0.15), 2px 2px 2px rgba(0, 0, 0, 0.1),
    -3px -3px 2px rgba(255, 255, 255, 0.05),
    -2px -2px 1px rgba(255, 255, 255, 0.05);
  overflow: hidden;
  cursor: pointer;
  z-index: 7;
  right: 3%;
  top: 13%;
}
.edit-button-span {
  position: relative;
  z-index: 2;
  transition: all 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}
/* 编辑按钮结束 */

//  卡片底部留言

/* 结束 */

.container {
  display: flex;
  position: relative;
  flex-wrap: wrap; /* 当超出容器宽度时自动换行 */

  height: 100%;
  justify-content: center;
  align-items: center;
}
.card {
  padding: 20px;
  display: flex;
  width: 330px;
  position: relative;
  flex-direction: column;
  justify-content: space-between;
  height: 480px;
  border-radius: 20px;
  background: #e8e8e8;
  box-shadow: 2px 2px 4px #dadada, -2px -2px 4px #f6f6f6;
  transition: 0.4s;
  margin-left: 26px;
  margin-bottom: 10px;
}
.footer {
  display: flex;
  justify-content: right;
  align-items: center;
}

.card:hover {
  translate: 0 -10px;
}

.card-title {
  font-size: 18px;
  font-weight: 600;
  color: #2e54a7;
  margin: 15px 0 0 10px;
}

.card-image {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 170px;
  overflow: hidden;
  background-color: #c9c9c9;
  border-radius: 15px;
  box-shadow: inset 8px 8px 10px #c3c3c3, inset -8px -8px 10px #cfcfcf;
}
.card-image > img {
  width: 100%;
  height: 100%;
}
.card-body {
  margin: 13px 0 0 10px;
  color: rgb(31, 31, 31);
  font-size: 15px;
  min-height: 80px;
}

.footer {
  float: right;
  margin: 28px 0 0 18px;
  font-size: 13px;
  color: #636363;
}

.by-name {
  font-weight: 700;
}

// 底部卡片评论留言区
/*卡牌图片底部评论 */
/* 底部留言 */
.card-footer {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  margin-top: 30px;
}

.icon {
  width: 25px;
  height: 25px;
}
.cardUserInfo {
  display: flex;
  justify-content: center;
  align-items: center;
}
.uesrInfo-img {
  width: 60px;
  height: 60px;
  overflow: hidden;
  border: 1px solid #f3f690;
  border-radius: 100%;
  margin-right: 25px;
}
.uesrInfo-img > span {
  padding: 2px;
}
.comLike {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0 20px;
  margin-right: 5px;
}
.comment {
  display: flex;
  justify-content: center;
  flex-direction: column;
  cursor: pointer;
}

.foot-com {
  display: flex;
  padding-left: 20px;
}
.foot-com > span {
  padding-left: 6px;
  opacity: 0.7;
}
.comment > span {
  margin-bottom: -30px;
  padding-top: 6px;
  padding-left: 25px;
  opacity: 0.5;
}
/* 抽屉用户评论 */
.user-comments {
  display: flex;
  flex-direction: column;
  max-height: 80%;
  overflow: auto;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  height: 370px;
  border: 2px solid #959ff8;
  background-color: #7dbbe7a7;
}

/*定义滚动条宽度和颜色*/
.user-comments::-webkit-scrollbar {
  width: 4px;
}

.user-comments::-webkit-scrollbar-track {
  background: #d2f3ef;
}

.user-comments::-webkit-scrollbar-thumb {
  background: #94f0f0;
}

/* 悬停效果 */
.user-comments::-webkit-scrollbar-thumb:hover {
  background: #5cd0f4;
}
.each-comments {
  width: 100%;
  display: flex;

  justify-content: flex-start;
  align-items: flex-end;
  margin-top: 20px;
}
.comment-words {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
}
.comment-words > P {
  padding: 3px;
  padding-left: 6px;
  font-size: 0.8rem;
  opacity: 0.5;
}
.comment-words > span {
  font-size: 0.9rem;
  padding-top: 7px;
  min-height: 20px;
  min-width: 70%;
  margin-left: 7px;
  margin-right: 10px;
  padding: 3px;
  background-color: #e8e8e8;
}

.comInfo {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 30%;
}
.comInfo > p {
  opacity: 0.6;
  font-size: 0.8rem;
}
.comInfo > div {
  width: 50px;
  height: 50px;
  border-radius: 100%;
  border: 3px solid #959ff8;
  overflow: hidden;
}

.comInfo > div > img {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

/* 抽屉评论 */
::v-deep .el-drawer__body {
  width: 95%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}
::v-deep .el-drawer.rtl {
  height: 100%;
  background-color: #b6dbfe;
  border-radius: 10px;
  right: 2%;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
::v-deep .el-drawer__container {
  position: relative;

  display: flex;

  left: 0;
  right: 10%;
  top: 50%;
  transform: translateY(-50%);
  bottom: 0;
  height: 90%;
  width: 100%;
}

::v-deep .el-drawer__wrap.draw-comments {
  background-color: #98c5e5;
}
/* 留言板块 */
.feedback-form {
  background: #a9cfff;
  border: 1px solid #8597b1;
  height: 34%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin-bottom: 20px;
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
}

.form-title {
  text-align: center;
  color: #9ca3af;
  font-size: 20px;
  font-weight: bold;
}

.feedback-input {
  background: #a0bbe1;
  height: 100px;
  border: 1px solid #a9c9ff;
  margin-top: 3px;
  color: #4b5563;
  width: 95%;
  resize: none;
  outline: none;
  border-radius: 5px;
  padding: 10px;
  transition: border-color 0.3s;
}

.submit-button {
  fill: #d1d5db;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 5px;
  padding: 10px;
  transition: all 0.3s;
  border: 1px solid #4b5563;
  background: #4b5563;
  cursor: pointer;
}

.submit-button:hover {
  fill: #d1d5db;
  border: 1px solid #4b5563;
  background: #2563eb;
}

.secondary-button {
  stroke: #d1d5db;
  background: #4b5563;
  border: 1px solid #4b5563;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 5px;
  padding: 3px;
  padding-top: 10px;
  transition: all 0.3s;
  cursor: pointer;
}

.secondary-button:hover {
  stroke: #2563eb;
  border: 1px solid #4b5563;
  background: #2563eb;
}

.spacer {
  margin-top: 20px;
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: flex-end;
}
/* 留言结束 */
</style>